package com.cjm.algorithm.leetcode;

import com.cjm.algorithm.TreeNode;

public class IsSameTree100 {
    public static boolean isSameTree(TreeNode p, TreeNode q) {
        return sameTree(p, q);
    }

    private static boolean sameTree(TreeNode p, TreeNode q) {
        if (p == null && q != null) {
            return false;
        }
        if (p != null && q == null) {
            return false;
        }
        if (p == null && q == null) {
            return true;
        }
        if (p.val != q.val) {
            return false;
        }
        boolean b = sameTree(p.left, q.left);
        if (!b) {
            return false;
        }
        boolean b1 = sameTree(p.right, q.right);
        if (!b1) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        System.err.println(
                isSameTree(
                        TreeNode.generatorTreeNode(new Integer[]{1, 2}),
                        TreeNode.generatorTreeNode(new Integer[]{1, null, 3})));
    }
}
